package net.cloudcodex.client.storyboard.player.view;

import net.cloudcodex.client.widgets.CharacterAvatar;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.inject.Inject;

public class MessageViewImpl extends FlowPanel implements MessageView {
	private final Constant constant;

	private final Label action = new Label();
	private final Label content = new Label();

	private CharacterAvatar character = new CharacterAvatar();

	@Inject
	public MessageViewImpl(Constant constant) {
		this.constant = constant;

		this.action.addStyleName(constant.getContentStyle());
		this.add(this.action);
		final Label actionSep = new Label("/");
		actionSep.addStyleName(constant.getContentStyle());
		this.add(actionSep);
		this.content.addStyleName(constant.getContentStyle());
		this.add(this.content);
	}

	@Override
	public void setCharacter(String name, String icon,Long id) {
		this.character.initComponent(icon, name);
		this.character.removeAvatarStyleName();
		this.character.addStyleName(constant.getContentStyle());
		this.character.setId(id);
		this.character.resize("50", "50");
		
		this.insert(this.character, 0);
		final Label authorSep = new Label(": ");
		authorSep.addStyleName(constant.getContentStyle());
		this.insert(authorSep, 1);
	}

	@Override
	public void setAction(String action) {
		this.action.setText(action);
	}

	@Override
	public void setContent(String content) {
		this.content.setText(content);
	}

	@Override
	public HasClickHandlers getAvatar() {
		return this.character ;
		
	}
}
